//package com.example.java.kafka.es9client;
//
//import co.elastic.clients.elasticsearch.ElasticsearchClient;
//import co.elastic.clients.json.jackson.JacksonJsonpMapper;
//import co.elastic.clients.transport.ElasticsearchTransport;
//import co.elastic.clients.transport.rest_client.RestClientTransport;
//import org.apache.http.HttpHost;
//import org.elasticsearch.client.RestClient;
//
//public class ConnectElasticsearch {
//    public static void connect(ElasticsearchTask task) {
//        // 创建低级 REST 客户端
//        RestClient restClient = RestClient.builder(
//                new HttpHost("localhost", 9200, "http") // 若启用 HTTPS，请改为 https
//        ).build();
//        // 创建传输层（使用 Jackson 序列化）
//        ElasticsearchTransport transport = new RestClientTransport(
//                restClient,
//                new JacksonJsonpMapper()
//        );
//        // 创建高级客户端
//        ElasticsearchClient client = new ElasticsearchClient(transport);
//        try {
//            // 执行任务
//            task.doSomething(client);
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                restClient.close();
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    }
//}
//
//@FunctionalInterface
//interface ElasticsearchTask {
//    void doSomething(ElasticsearchClient client) throws Exception;
//}